<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/commons/global.jsp"%>

<div id="categoryAudioAddListList-div" class="easyui-window"
	title="分类音频配置" style="width: 96%; height: 96%;"
	data-options="iconCls:'icon-cog',modal:true,openAnimation:'fade',closeAnimation:'slide',cache:false,collapsible:false,minimizable:false,maximizable:false">

	<table id="categoryAudioAddListList" style="height: 100%; width: 100%;">

	</table>

</div>

<div id="categoryAudioAddListListToolBars" style="height: auto;">
	<a href="javascript:void(0)" class="easyui-linkbutton"
		data-options="iconCls:'icon-add',plain:true"
		onclick="categoryAudioAddListList_categoryListPage()">添加</a> |<input
		id="categoryAudioAddListList_AudioListStatusQue" style="width: 100px;" />
	|<input id="categoryAudioAddListList_AudioListTitleQue"
		style="width: 200px;" />
</div>

<script type="text/javascript">
	function categoryAudioAddListListDatagridReload() {
		try {
			var queryParams = {
				like_title : categoryAudioAddListList_AudioListTitleQue
						.textbox('getValue'),
				status : categoryAudioAddListList_AudioListStatusQue
						.combobox('getValue')
			};
			categoryAudioAddListListDatagrid.datagrid("options").queryParams = queryParams;
			categoryAudioAddListListDatagrid.datagrid("reload");
		} catch (e) {
		}
	}
</script>

<script type="text/javascript">
	var categoryAudioAddListList_AudioListStatusQue = undefined;
	var categoryAudioAddListList_AudioListTitleQue = undefined;
	var categoryAudioAddListSelectIndex = undefined;
	var categoryAudioAddListSelectRow = undefined;
	var categoryAudioAddListEditIndex = undefined;
	var categoryAudioAddListEditRow = undefined;
	var categoryAudioAddListListDatagrid = undefined;
	$(function() {
		categoryAudioAddListList_AudioListStatusQue = $(
				'#categoryAudioAddListList_AudioListStatusQue').combobox({
			data : [ {
				"statusCode" : 0,
				"statusMsg" : "全部音频状态",
				"selected" : true
			}, {
				"statusCode" : 1,
				"statusMsg" : "已发布"
			}, {
				"statusCode" : 2,
				"statusMsg" : "已下线"
			}, {
				"statusCode" : 3,
				"statusMsg" : "待发布"
			} ],
			valueField : 'statusCode',
			textField : 'statusMsg',
			onChange : function(newValue, oldValue) {
				categoryAudioAddListListDatagridReload();
			}
		});

		categoryAudioAddListList_AudioListTitleQue = $(
				'#categoryAudioAddListList_AudioListTitleQue').textbox({
			buttonText : '标题搜索',
			buttonIcon : 'icon-search',
			buttonAlign : 'right'
		});

		categoryAudioAddListList_AudioListTitleQue.textbox('button').click(
				function() {
					categoryAudioAddListListDatagridReload();
				});

		$('.easyui-linkbutton').linkbutton();
		var categoryAudioAddListList_div = $('#categoryAudioAddListList-div')
				.window({
					onBeforeClose : function() {

					},
					onClose : function() {
						categoryAudioAddListList_div.panel('destroy');
						try {
							categoryAudioListDatagrid.datagrid('reload');
						} catch (e) {
						}
					}
				});

		categoryAudioAddListListDatagrid = $('#categoryAudioAddListList')
				.datagrid(
						{
							url : '${baseUrl}/audio/list',
							pagination : true,
							sortName : 'sort,updateTime',
							sortOrder : 'desc,desc',
							multiSort : true,
							//remoteSort : false,
							// 			rownumbers : true,
							queryParams : {},
							singleSelect : true,
							idField : 'id',
							striped : true,
							pageSize : 20,
							fitColumns : true,
							toolbar : '#categoryAudioAddListListToolBars',
							onLoadSuccess : function() {
								categoryAudioAddListSelectIndex = undefined;
								categoryAudioAddListSelectRow = undefined;
								categoryAudioAddListEditIndex = undefined;
								categoryAudioAddListEditRow = undefined;
							},
							onBeforeSelect : function(index, row) {
								if (categoryAudioAddListEditIndex != undefined) {
									return false;
								} else {
									categoryAudioAddListSelectIndex = index;
									categoryAudioAddListSelectRow = row;
								}
							},
							onBeforeEdit : function(index, row) {
								if (categoryAudioAddListEditIndex == undefined) {
									categoryAudioAddListEditIndex = index;
									categoryAudioAddListEditRow = row;
								}
							},
							onEndEdit : function(index, row, changes) {
								var _ed = $(this).datagrid('getEditor', {
									index : index,
									field : 'statusCode'
								});
								row.statusMsg = $(_ed.target).combobox(
										'getText');
							},
							// 			nowrap : false,
							columns : [ [
									{
										field : 'cover_url',
										title : '封面',
										width : 100,
										align : 'center',
										formatter : function(value, row, index) {
											if (row.coverUrl) {
												var img = '<img src="'
														+ row.coverUrl
														+ '" style="width:103%;height:100px;"/>';
												return img;
											} else {
												return value;
											}
										}
									},
									{
										field : 'id',
										title : 'ID',
										align : 'center',
										width : 60
									},
									{
										field : 'title',
										title : '标题',
										width : 249,
										editor : {
											type : 'text',
											options : {
												required : true
											}
										}
									},
									{
										field : 'sources',
										title : '资源',
										align : 'center',
										width : 100
									},
									{
										field : 'skey',
										title : '资源令牌',
										width : 100,
										align : 'center',
										hidden : true
									},
									{
										field : 'createTime',
										title : '创建时间',
										width : 100,
										align : 'left'
									},
									{
										field : 'updateTime',
										title : '更新时间',
										width : 100,
										align : 'left',
										sortable : true
									},
									{
										field : 'createUser',
										title : '创建者',
										width : 60,
										align : 'center',
										formatter : function(value, row, index) {
											if (row.createUser) {
												return row.createUser.nickname;
											} else {
												return value;
											}
										}
									},
									{
										field : 'entity',
										title : '音频实体',
										width : 80,
										align : 'center',
										formatter : function(value, row, index) {
											return value;
										}
									},
									{
										field : 'parent',
										title : '所属音频集合',
										width : 249,
										align : 'left',
										formatter : function(value, row, index) {
											if (row.parent) {
												return "<span>集合ID:"
														+ row.parent.id
														+ "</span><br/><span>集合标题:"
														+ row.parent.title
														+ "</span>";
											} else {
												return value;
											}
										}
									},
									{
										field : 'sort',
										title : '排序',
										width : 60,
										align : 'center',
										sortable : true,
										editor : {
											type : 'numberbox',
											options : {
												min : 0,
												precision : 2,
												required : true
											}
										}
									},
									{
										field : 'summary',
										title : '简介',
										width : 100,
										align : 'left',
										editor : {
											type : 'textarea'
										}
									},
									{
										field : 'info',
										title : '详细介绍',
										width : 100,
										align : 'left',
										editor : {
											type : 'textarea'
										}
									},
									{
										field : 'playtime',
										title : '播放时间(秒)',
										width : 100,
										align : 'center',
										editor : {
											type : 'numberbox',
											options : {
												min : 0,
												required : true
											}
										}
									},
									{
										field : 'statusCode',
										title : '状态',
										width : 80,
										align : 'center',
										formatter : function(value, row, index) {
											var statusCodeSpan = '<span style="';
											if (row.statusCode == 1) {
												statusCodeSpan += 'color:#6B8E23;font-size:13px;font-weight:600;';
											} else if (row.statusCode == 2) {
												statusCodeSpan += 'color:#8B4726;font-size:13px;font-weight:600;';
											} else if (row.statusCode == 3) {
												statusCodeSpan += 'color:#104E8B;font-size:13px;font-weight:600;';
											}
											return statusCodeSpan += '">'
													+ row.statusMsg + '</span>';
										}
									},
									{
										field : 'progressStatusCode',
										title : '进度',
										width : 80,
										align : 'center',
										formatter : function(value, row, index) {
											var statusCodeSpan = '<span style="';
											if (row.progressStatusCode == 2) {
												statusCodeSpan += 'color:#6B8E23;font-size:13px;font-weight:600;';
											} else if (row.progressStatusCode == 1) {
												statusCodeSpan += 'color:#FFEC8B;font-size:13px;font-weight:600;';
											}
											return statusCodeSpan += '">'
													+ row.progressStatusMsg
													+ '</span>';
										}
									} ] ],
							onDblClickRow : function(index, row) {
								$.ajax({
									data : {
										id : row.id
									},
									async : false,
									url : baseUrl + '/audio/info.html',
									success : function(html) {
										$('body').append(html);
									}
								});

							}
						});

		categoryAudioAddListListDatagrid.datagrid('getPager').pagination(
				{
					buttons : [ {
						iconCls : 'fa fa-2x fa-location-arrow',
						handler : function() {
							categoryAudioAddListListDatagrid.datagrid(
									'gotoPage',
									categoryAudioAddListListDatagrid.datagrid(
											'getPager').find('.pagination-num')
											.val());
						}
					} ]
				});

	});

	function categoryAudioAddListList_append() {

		$.ajax({
			url : baseUrl + '/categoryAudioAddList/add/page.html',
			success : function(html) {
				$('body').append(html);
			}
		});
	}

	function categoryAudioAddListList_categoryListPage() {
		var categoryAudioAddListSelect = categoryAudioAddListListDatagrid
				.datagrid('getSelected');
		if (categoryAudioAddListSelect) {
			$.ajax({
				data : {
					itemId : categoryAudioAddListSelect.id,
					itemType : 2
				},
				async : false,
				url : baseUrl + '/category/set.html',
				success : function(html) {
					$('body').append(html);
				}
			});
		}
	}
</script>

